import { defineStore } from 'pinia'
import { ref } from 'vue'
import { templateAPI } from '@/services/api'

export const useExperimentStore = defineStore('experiment', () => {
  const experimentList = ref([])
  const currentExperiment = ref(null)

  // 获取实验列表
  const fetchExperimentList = async () => {
    try {
      const response = await templateAPI.getExperiments()
      experimentList.value = response.data || []
    } catch (error) {
      console.error('Error fetching experiment list:', error)
    }
  }

  // 设置当前选中的实验
  const setCurrentExperiment = (experiment) => {
    currentExperiment.value = experiment
  }

  // 获取当前选中的实验
  const getCurrentExperiment = () => {
    return currentExperiment.value
  }

  return {
    experimentList,
    currentExperiment,
    fetchExperimentList,
    setCurrentExperiment,
    getCurrentExperiment
  }
}) 